#include "ServerManager.h"
#include "Timer.h"

#include <iostream>

ServerManager::ServerManager()
{
	m_isServer = false;
}

void ServerManager::CheckPing()
{
	TheTimer::Instance()->UpdateTime();
	m_sock.CheckMaxPing();
}

void ServerManager::AddClient(ClientSocket* cs)
{
	m_sock.AddClient(cs);
}

bool ServerManager::SendGameMessageToAll(GameMessage& gm)
{
	return m_sock.SendGameMessageToAll(gm);
}

Socket* ServerManager::Accept()
{
	return m_sock.Accept();
}

bool ServerManager::Open(int port)
{
	if (m_sock.Open(port))
	{
		m_isServer = true;
		return true;
	}
	return false;
}

ServerSocket& ServerManager::GetSocket()
{
	return m_sock;
}

bool ServerManager::GetIsServer() const
{
	return m_isServer;
}

ClientSocket& ServerManager::GetClient(int id) const
{
	return m_sock.GetClient(id);
}

void ServerManager::SetClientPosition(int clientID, const D3DXVECTOR3& pos)
{
	m_sock.SetClientPosition(clientID, pos);
}